package com.techshine.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.techshine.common.base.BaseController;
import com.techshine.entity.Equ;
import com.techshine.service.EquService;
import com.techshine.util.StringUtil;
/** 
 * 说明：设备
 * 创建时间：2024-04-18
 */
@Controller
@RequestMapping(value="/equ")
public class EquController extends BaseController {
	
	
	@Resource
	private EquService equService;
	
	
	@ResponseBody 
    @RequestMapping("/queryByKey")
    public Map<String, Object>  queryByKey(String id) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(id)){
			Equ entity = equService.queryByKey(id);
			map.put("result", entity);
			map.put("status", 200);
    	}else{
    		map.put("msg", "参数错误");
			map.put("status", 902);
    	}
		return map;
    }
   
    @ResponseBody 
    @RequestMapping("/queryListByPage")
    public Map<String, Object> queryListByPage(Equ entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		List<Equ> list = equService.queryListByPage(entity);
		map.put("code", 0); 
		map.put("data", list);
		map.put("count", entity.getCount());
		return map;
    }
    @ResponseBody 
    @RequestMapping("/queryList")
    public Map<String, Object> queryList(Equ entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		
		List<Equ> list = equService.queryList(entity);
		map.put("status", 200);
		map.put("result", list);
		
		return map;
    }
    @ResponseBody 
    @RequestMapping("/insert")
    public Map<String, Object> insert(Equ entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		//entity.setId(NumberUtil.randomUUID());
		//entity.setCreateTime(DateUtil.getCurrentDate());
		//entity.setUpdateTime(DateUtil.getCurrentDate());
    	if(entity.getId()!=null&&entity.getId()>0) {
    		equService.updateByKeySelective(entity);
    	}else {
    		equService.insertSelective(entity);
    	}
		map.put("status", 200);
		map.put("msg", "成功!");
		
		return map;
    }
    @ResponseBody 
    @RequestMapping("/update")
    public Map<String, Object> update(Equ entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		
		//entity.setUpdateTime(DateUtil.getCurrentDate());
		if(StringUtil.isNotEmpty(entity.getId())){
			equService.updateByKeySelective(entity);
			map.put("result", entity);
			map.put("status", 200);
    	}else{
    		map.put("msg", "参数错误");
			map.put("status", 902);
    	}
		return map;
    }
    @ResponseBody 
    @RequestMapping("/delete")
    public Map<String, Object> delete(Equ entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
    	
		if(StringUtil.isNotEmpty(entity.getId())){
			equService.delete(entity);
			map.put("result", entity);
			map.put("status", 200);
    	}else{
    		map.put("msg", "参数错误");
			map.put("status", 902);
    	}
		return map;
    }
  
	
	 /**批量删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public Map<String, Object> deleteAll() throws Exception{
		
		return null;
	}
	@RequestMapping(value="/updatestas")
	@ResponseBody
	public Map<String, Object> updatestas(String ids,String category) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(ids)){
			equService.updatestas(ids,category);
			map.put("status", 200);
    	}else{
    		map.put("msg", "参数错误");
			map.put("status", 902);
    	}
		return map;
	}
	
	@RequestMapping(value="/delmore")
	@ResponseBody
	public Map<String, Object> delmore(String ids) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(ids)){
			equService.delmore(ids);
			map.put("status", 200);
    	}else{
    		map.put("msg", "参数错误");
			map.put("status", 902);
    	}
		return map;
	}
}
